<?php

namespace App\Exceptions;

use Exception;
use http\Env\Response;
use Throwable;

class PermissionException extends Exception
{
    public function __construct(string $message = "", int $code = 0, Throwable $previous = null)
    {
        parent::__construct($message, $code, $previous);
    }

    public function render($request){
//        dd($request->toArray());
//        return response()->json(['code'=>$this->code,'message'=>$this->getMessage()],403);
        if ($request->expectsJson()){
//            dd(111);
            return response()->json(['message'=>$this->getMessage(),$this->code],403);
        }
        return back()->with('warning',$this->getMessage());
}
}
